package com.liao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liao.bean.News;
import com.liao.bean.result.Msg;
import com.liao.bean.result.PageResult;
import com.liao.dao.NewsDao;
import com.liao.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {

    @Autowired
    private NewsDao newsDao;

    @Override
    public PageResult<News> queryNewsListByPage(Integer currentPage, Integer pageSize, String newsTitle) throws Exception {
        PageHelper.startPage(currentPage,pageSize);
        //查询所有菜单
        List<News> newsList = newsDao.selectNewsListLikeNewsName(newsTitle);
        PageInfo<News> pageInfo = new PageInfo<>(newsList);
        return new PageResult<>(0, Msg.NEWS_QUERY_SUCCESS,pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public void addNews(News news) throws Exception {
        newsDao.addNews(news);
    }

    @Override
    public void editNews(News news) throws Exception {
        newsDao.updateNews(news);
    }

    @Override
    public void deleteNews(String newsId) throws Exception {
        newsDao.deleteNews(newsId);
    }
}
